package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.UserLocation;
import com.qinggeng.project.system.service.IUserLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 用户位置Controller
 *
 * @author qinggeng
 * @date 2020-06-26
 */
@RestController
@RequestMapping("/system/location")
public class UserLocationController extends BaseController
{
    @Autowired
    private IUserLocationService userLocationService;

    /**
     * 查询用户位置列表
     */
    @PreAuthorize("@ss.hasPermi('system:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserLocation userLocation)
    {
        startPage();
        List<UserLocation> list = userLocationService.selectUserLocationList(userLocation);
        return getDataTable(list);
    }

    /**
     * 导出用户位置列表
     */
    @PreAuthorize("@ss.hasPermi('system:location:export')")
    @Log(title = "用户位置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserLocation userLocation)
    {
        List<UserLocation> list = userLocationService.selectUserLocationList(userLocation);
        ExcelUtil<UserLocation> util = new ExcelUtil<UserLocation>(UserLocation.class);
        return util.exportExcel(list, "location");
    }

    /**
     * 获取用户位置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:location:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(userLocationService.selectUserLocationById(userId));
    }

    /**
     * 新增用户位置
     */
    @PreAuthorize("@ss.hasPermi('system:location:add')")
    @Log(title = "用户位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserLocation userLocation)
    {
        return toAjax(userLocationService.insertUserLocation(userLocation));
    }

    /**
     * 修改用户位置
     */
    @PreAuthorize("@ss.hasPermi('system:location:edit')")
    @Log(title = "用户位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserLocation userLocation)
    {
        return toAjax(userLocationService.updateUserLocation(userLocation));
    }

    /**
     * 删除用户位置
     */
    @PreAuthorize("@ss.hasPermi('system:location:remove')")
    @Log(title = "用户位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(userLocationService.deleteUserLocationByIds(userIds));
    }
}
